#ifndef CCheckBH
#define CCheckBH

#include <SysUtils.hpp>
#include <sysinit.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <winuser.h>
#include "CtrlStd.h"
#include "Messages.h"

#define DEFAULT_WIDTH       110
#define DEFAULT_HEIGHT       17
#define SIZE_ESP              5
#define COL_EDIT_CHKBX                  clWindow

#define CM_CHANGECOLOR (WM_APP + 400)

enum TCheckBoxAlign { eChkBxLeftAlign, eChkBxRightAlign };
enum StateChkBx     { eChkBxChecked, eChkBxUnChecked, eChkBxDisabledChecked, eChkBxDisabledUnChecked };


class PACKAGE_CTRLSTD  CCheckBox: public TCustomControl
	{
	private:
		typedef TCustomControl inherited;
		typedef void __fastcall (__closure *TNotifyEvent)(System::TObject* Sender, bool bIsChecked );
		bool                FChecked;
		bool                FReadOnly;
		enum TCheckBoxAlign FAlignment;
		TNotifyEvent 		    FOnCheck;
    AnsiString          FReference;

	__published:
		__property enum TCheckBoxAlign  Alignment   = { read=FAlignment,    write=SetAlignment, default = eChkBxLeftAlign    };
		__property                      Color;
		__property                      Caption     = { read=GetCaption,    write=SetCaption,   default = NULL          };
		__property bool                 Checked     = { read=FChecked,      write=SetChecked,   default = false         };
		__property                      DragCursor;
		__property                      DragMode;
		__property                      Enabled     = { read=GetEnabled,    write=SetEnabled,   default = true          };
		__property                      Font;
		__property                      HelpContext;
		__property                      Hint;
		__property                      ParentColor;
		__property                      ParentFont;
		__property                      ParentShowHint;
		__property                      PopupMenu;
		__property bool                 ReadOnly    = { read=FReadOnly,     write=SetReadOnly,  default = false         };
		__property                      ShowHint;
		__property                      TabOrder;
		__property                      TabStop;
		__property                      Visible;
		__property                      Anchors;
    __property AnsiString           Reference = { read=FReference, write=FReference};

		// Evenements
		__property OnStartDrag;
		__property OnDragDrop;
		__property OnDragOver;
		__property OnEndDrag;
		__property OnKeyDown;
		__property OnKeyPress;
		__property OnKeyUp;
		__property OnEnter;
		__property OnExit;
		__property OnMouseDown;
		__property OnMouseMove;
		__property OnMouseUp;
		__property OnClick;
		__property OnDblClick;
		__property TNotifyEvent OnCheck = {read=FOnCheck, write=FOnCheck};

    AnsiString __fastcall GetReference( void);


	private:
		void        __fastcall SetAlignment(    enum TCheckBoxAlign AAlignment  );
		void        __fastcall SetCaption(      const AnsiString    aCaption    );
		void        __fastcall SetChecked(      bool                bChecked    );
		void        __fastcall SetEnabled(      bool                bEnabled    );
		void        __fastcall SetReadOnly(     bool                bReadOnly   );
		AnsiString  __fastcall GetCaption() /*const*/;
		bool        __fastcall GetEnabled();

	private:
		Graphics::TBitmap   *BmpCheck;
		TLabel              *LCaption;
		bool                bFocused;
		bool				bCheckedFromClick;

	protected:
		virtual void __fastcall Paint();
		virtual void __fastcall WndProc( TMessage &Message );
		DYNAMIC void __fastcall Click();
//		DYNAMIC void __fastcall KeyDown(Word &Key, Classes::TShiftState Shift);

		DYNAMIC void __fastcall KeyPress( char &Key );
		void __fastcall CaptionClick(   TObject *Sender );
		void __fastcall DrawContour(    bool bVisible );
		void __fastcall DrawCheck( enum StateChkBx eState );


	private:
		void __fastcall LoadBmpCheck();
		void __fastcall InitCaption();

	public:
		__fastcall CCheckBox(TComponent* Owner);
   virtual __fastcall ~CCheckBox( void);
	};
#endif
